//
//  CellDetailsViewController.m
//  DemoSecond
//
//  Created by yuzhuo on 16/7/19.
//  Copyright © 2016年 yuzhuo. All rights reserved.
//

#import "CellDetailsViewController.h"
#import "Constant.h"
#import "SelfTableCell.h"
#import "SelfTopViewCell.h"
#import "SelfInfoEditViewController.h"
#import "SettingViewController.h"
#import "PickupController.h"

@interface CellDetailsViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) UITableView * tabView;
/** userInfoEntity */
@property (nonatomic,strong)  UserInfoEnity *userdata;
/** data */
@property (nonatomic,strong) NSMutableArray<NSString *> *data;
@end

@implementation CellDetailsViewController

-(instancetype) init
{
    self = [super init];
    if(self){
        self.tabView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStyleGrouped];
        
        self.tabView.dataSource = self;
        self.tabView.delegate = self;
        [self initData];
    }
    return self;
}

-(void) initData{
    _userdata = [UserInfoEnity new];
    _data = [NSMutableArray new];
    _userdata.userName = @"傻颖弟";
    _userdata.avatar = [UIImage imageNamed:@"default_parents"];

    [_data addObject:@"我的发表"];
    [_data addObject:@"我的收藏"];
    [_data addObject:@"意见反馈"];
    [_data addObject:@"设置"];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blackColor];
    [self.view addSubview:self.tabView];
    self.tabView.frame = self.view.bounds;
    //    self.tabView.backgroundColor = [UIColor whiteColor];
    [self.tabView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight ];
    self.tabView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    self.title = @"个人中心";
    
    // Do any additional setup after loading the view, typically from a nib.
}

-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
    return self.data.count+1;
    
}

-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.001f;
}

-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 15;
}


-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == 0){
        return 110;
    }else{
        return 50;
    }
}

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    if(indexPath.section == 0){
        static NSString *cellID = @"topcellID";
        SelfTopViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if(cell == nil){
            cell = [[SelfTopViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        
        cell.data = self.userdata;
        
        return cell;
    }else{
        static NSString *cellID = @"cellID";
        SelfTableCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
        if(cell == nil){
            cell = [[SelfTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        if(indexPath.section < self.data.count+1){
            cell.data = self.data[indexPath.section-1];
        }
        return cell;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    if(indexPath.section == 0){
            SelfInfoEditViewController *detailview = [SelfInfoEditViewController new];
            NSLog(@"click row%ld",indexPath.row);
            [self.navigationController pushViewController:detailview animated:YES];
    }
    if(indexPath.section == 4){
        SettingViewController *detailview = [SettingViewController new];
        NSLog(@"click row%ld",indexPath.row);
        [self.navigationController pushViewController:detailview animated:YES];
    }
    if(indexPath.section == 1 ||indexPath.section == 2){
        PickupController *detailview = [PickupController new];
        if(indexPath.section == 1)
            detailview.titleName = @"我的发表";
        if(indexPath.section == 2)
            detailview.titleName = @"我的收藏";
        NSLog(@"click row%ld",indexPath.row);
        [self.navigationController pushViewController:detailview animated:YES];
    }

}

@end
